#include "GSRankChange.h"

GSRankChange::GSRankChange()
{
	SetStateName("GSRANKCHANGE");
}

GSRankChange::GSRankChange(bool rankup)
{
	SetStateName("GSRANKCHANGE");
	isRankUp = rankup;
}

GSRankChange::~GSRankChange()
{
	DEVICE->GetDriver()->removeTexture(sprBG);
}

void GSRankChange::OnEnter()
{
	if(isRankUp)
		sprBG = Game::GetDevice()->GetDriver()->getTexture("data/sprites/bg/sprRankUp.png");
	else
		sprBG = Game::GetDevice()->GetDriver()->getTexture("data/sprites/bg/sprRankDown.png");
	fontCustomBig = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/Showcard_Gothic.png");
	fontCustom = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/fontcourier.bmp");
	fontCustomBig2 = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/bigfont.png");
	fontCustom2 = Game::GetDevice()->GetInstance()->getGUIEnvironment()->getFont("data/strings/mv_boli.png");
	bgBox = core::rect<s32>(0,0,SCREEN_WIDTH, SCREEN_HEIGHT);

	isShowEnterText = true;
	deltaTime = NULL;

	newRank = "";
	switch(PLAYER->GetRank())
	{
	case RANK_A:
		{
			newRank += "RANK A";
			break;
		}
	case RANK_B:
		{
			newRank += "RANK B";
			break;
		}
	case RANK_C:
		{
			newRank += "RANK C";
			break;
		}
	case RANK_D:
		{
			newRank += "RANK D";
			break;
		}
	case RANK_E:
		{
			newRank += "RANK E";
			break;
		}
	case RANK_F:
		{
			newRank += "RANK F";
			break;
		}
	}
}

void GSRankChange::OnExit()
{

}

void GSRankChange::Update()
{
	gameTime = DEVICE->GetInstance()->getTimer()->getTime();
	if(deltaTime == NULL)
	{
		deltaTime = gameTime;
	}
	if(gameTime - deltaTime >= 1000)
	{
		isShowEnterText = !isShowEnterText;
		deltaTime = NULL;
	}
	if(DEVICE->receiver.IsKeyUp(KEY_RETURN))
		Game::PopState();
}

void GSRankChange::Render()
{
	Game::GetDevice()->GetDriver()->beginScene(true, true, video::SColor(255,255,255,255));

	Game::GetDevice()->GetDriver()->draw2DImage(sprBG, core::position2di(0, 0), bgBox, 0, video::SColor(255,255,255,255), true);
	fontCustomBig2->draw(newRank, core::rect<s32>(SCREEN_WIDTH/2 - 100, SCREEN_HEIGHT/2 - 20, 100, 10), video::SColor(255,255,255,255));
	if(isShowEnterText)
		fontCustom2->draw("Enter to Continue", core::rect<s32>(SCREEN_WIDTH/2 - 100, 330,100,10), video::SColor(255,255,0,0));
	Game::GetDevice()->GetDriver()->endScene();
}